package com.article.controller;

import com.article.dto.ReturnError;
import com.article.enums.ReturnInfoEnum;
import com.article.model.AdminInfo;
import com.article.model.TestTime;
import com.article.service.AdminInfoService;
import com.article.service.TestTimeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Calendar;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2017/5/10.
 */
@RestController
@RequestMapping("/test")
public class TestController {
    private final static Logger log = LoggerFactory.getLogger(TestController.class);
    @Autowired
    private TestTimeService testTimeService;
    @Autowired
    private AdminInfoService adminInfoService;

    @RequestMapping(value = "/test")
    public ReturnError test() {
        try {

            TestTime testTime = new TestTime();
            //testTime.setGmtCreate(Calendar.getInstance().getTime());
            return testTimeService.saveTestTime(testTime);
        } catch (RuntimeException e) {
            e.printStackTrace();
            return new ReturnError(true, ReturnInfoEnum.ERROR.getType(), ReturnInfoEnum.ERROR.getInfo(), null);
        }
    }

    @RequestMapping("/tt")
    public ReturnError t() throws Exception {
        int i = 5 / 0;
        return new ReturnError(false, ReturnInfoEnum.SUCCESS.getType(), ReturnInfoEnum.SUCCESS.getInfo());
    }

    @RequestMapping(value = "/show")
    public ModelAndView show() {
        ModelAndView mav = new ModelAndView("aa");
        List<AdminInfo> adminInfoList = adminInfoService.listByMap(new HashMap<>());
        mav.addObject("adminInfoList", adminInfoList);
        return mav;
    }
}
